package com.wn.inventory.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wn.common.ActivitiStartEntity;
import com.wn.common.PageBean;
import com.wn.common.ResponseEntity;
import com.wn.entity.Hr;
import com.wn.entity.ReturnInWarehouseApplication;
import com.wn.inventory.feign.ActivitiFeignClient;
import com.wn.inventory.mapper.ReturnInWarehouseApplicationMapper;
import com.wn.inventory.service.ReturnInWarehouseApplicationService;
import com.wn.inventory.vo.ReturnInWarehouseApplicationVo;
import com.wn.utils.CurrentTime;
import com.wn.utils.PageBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ author     ：NST
 * @ date       ：Created in 2022/10/21 15:26
 * @ description：
 * @ modified By：
 * @ version:
 */
@Service
public class ReturnInWarehouseApplicationImpl implements ReturnInWarehouseApplicationService {
    @Autowired
    ReturnInWarehouseApplicationMapper returnInWarehouseApplicationMapper;
    @Autowired
    ActivitiFeignClient activitiFeignClient;
    /**
     * @param returnInWarehouseApplication
     * @return void
     * @ author nst
     * @ date 2022/10/21 15:28
     * @ Description 增加借用返还入库申请信息
     */
    @Override
    public void insert(ReturnInWarehouseApplication returnInWarehouseApplication, HttpServletRequest request) {
        returnInWarehouseApplication.setApplicant(new Hr(Integer.parseInt(request.getHeader("userId"))));
        returnInWarehouseApplication.setInWarehouseTime(CurrentTime.getCurrentTime());
        String identifier="RIWA"+CurrentTime.getCurrentTimeString();
        returnInWarehouseApplication.setIdentifier(identifier);
        ResponseEntity<String> entity = activitiFeignClient.startInstance(new ActivitiStartEntity("in_warehouss_application_id", "user1", request.getHeader("userWorkNumber")));
//        activitiFeignClient.completeTask(new ActivitiCompleteEntity("in_warehouss_application_id",entity.getData(),"user1",));
        returnInWarehouseApplication.setActivitiInstanceId(entity.getData());
        returnInWarehouseApplicationMapper.insert(returnInWarehouseApplication);
    }
    /**
     * @param returnInWarehouseApplicationVo
     * @return com.wn.common.PageBean<com.wn.entity.ReturnInWarehouseApplication>
     * @ author nst
     * @ date 2022/10/21 15:29
     * @ Description 多条件分页查询借用返还申请信息
     */
    @Override
    public PageBean<ReturnInWarehouseApplication> getByCondition(ReturnInWarehouseApplicationVo returnInWarehouseApplicationVo) {
        Page<ReturnInWarehouseApplication> page = PageHelper.startPage(returnInWarehouseApplicationVo.getCurrPage(), returnInWarehouseApplicationVo.getPageSize());
        List<ReturnInWarehouseApplication> list = returnInWarehouseApplicationMapper.getByCondition(returnInWarehouseApplicationVo.getReturnInWarehouseApplication());
        return PageBeanUtil.getPageBean(list, page, returnInWarehouseApplicationVo.getCurrPage(), returnInWarehouseApplicationVo.getPageSize());
    }
}
